// clock.c
#include"sbi.h"

unsigned long TIMECLOCK = 0x500000;

unsigned long get_cycles() {
    unsigned long ret_val;
    __asm__ volatile(
        "rdtime %[ret_val]"
        :[ret_val] "=r" (ret_val)
        : : "memory"
    );
    return ret_val;
}

void clock_set_next_event() {
    unsigned long next_time = get_cycles() + TIMECLOCK;
    sbi_set_timer(next_time);
} 